<template>
  <nav>
    <h1 class="title">{{ getTitle }}</h1>
    <div class="nav-container">
      <router-link :to="{path: '/cart', params: {title: 'Goods Cart'}}"
        :data-count="getCartGoodsNum > 99 ? 99 : getCartGoodsNum"
        class="shopping-cart"
        >🛒 购物车
      </router-link>
      <router-link to="/" class="goods">🎁 商品区</router-link>
    </div>
  </nav>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'Nav',
  computed: {
    ...mapGetters(['getCartGoodsNum']),
    getTitle () {
      let path = this.$route.path
      return path === '/cart' ? 'Cart' : 'Goods'
    }
  }
}
</script>

<style lang='scss'>
    nav{
        padding-top: 10px;
        overflow: hidden;
        padding-right: 60px;
        padding-bottom: 10px;
        background: white;
        position: fixed;
        border-bottom: 1px solid #cccccc;
        box-shadow: 0 0 2px 6px rgba(0,0,0,.1);
        top: 0;
        left: 0;
        width: 100%;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .nav-container{
          display: flex;
        }
        .title{
          margin: 0;
          font-size: 36px;
        }
        .shopping-cart, .goods{
          display: block;
          color: #66CCFF;
          text-decoration: none;
          cursor: pointer;
          padding: 6px 10px;
          margin: 0 6px;
          border: 2px solid #66CCFF;
          border-radius: 14px;
          &:hover{
            background: #66CCFF;
            color: white;
            font-weight: 600;
          }
        }
        .shopping-cart{
          position: relative;
          &::after{
            content: attr(data-count);
            position: absolute;
            left: 0;
            top: 0;
            height: 24px;
            width: 24px;
            background-color: #f22;
            color: white;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            font-size: 14px;
            transform: translateX(-50%);
          }
        }
    }
</style>
